<template>
  <div>
    <van-search placeholder="共239款好物" input-align="center" />
    <div class="content">
      <div class="left">
        <van-sidebar v-model="activeKey">
          <van-sidebar-item
            :title="item.name"
            v-for="item in categoryList"
            :key="item.id"
            @click="current(item)"
          />
        </van-sidebar>
      </div>
      <div class="right">
        <div class="banner">
          <img :src="currentOne.banner_url" alt />
        </div>
        <div class="title">--{{currentOne.name}}分类--</div>
        <div class="bottom">
          <router-link :to="`/category/detail?id=${list.id}`" class="item" v-for="list in subList" :key="list.id">
            <img :src="list.wap_banner_url" alt />
            <span>{{list.name}}</span>
          </router-link>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { indexaction, currentaction } from "@/api/nav";
export default {
  data() {
    return {
      activeKey: 0,
      categoryList: [],
      currentOne: [],
      subList: []
    };
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    current(item) {
      currentaction({
        id: item.id
      }).then(res => {
        console.log(res);
        console.log(res.data.currentOne.subList);
        this.currentOne = res.data.currentOne;
        this.subList = res.data.currentOne.subList;
      });
    }
  },
  created() {
    indexaction().then(res => {
      // console.log(res);
      this.categoryList = res.categoryList;
    });
    currentaction({
      id: 1005000
    }).then(res => {
      console.log(res);
      console.log(res.data.currentOne.subList);
      this.currentOne = res.data.currentOne;
      this.subList = res.data.currentOne.subList;
    });
  }
};
</script>

<style lang="scss" scoped>
.content {
  flex: 1;
  background: #fff;
  display: flex;
  overflow: auto;
  .left {
    width: 2.16rem;
    height: 100%;
    text-align: center;
  }
  .right {
    border-left: 0.01333rem solid #fafafa;
    flex: 1;
    height: 100%;
    padding: 0 0.4rem 0 0.4rem;
    .banner {
      width: 100%;
      height: 2.96rem;
      margin-top: 0.26667rem;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .title {
      text-align: center;
      padding: 0.66667rem 0;
    }
    .bottom {
      display: flex;
      flex-wrap: wrap;
      .item {
        display: inline-block;
        width: 33.33%;
        text-align: center;
        color: #4e4e4e;
        margin-bottom: 0.26667rem;
        img {
          height: 1.92rem;
          width: 1.92rem;
          display: block;
          margin: 0 auto;
        }
      }
    }
  }
}
</style>